package com.damacheng009.future.alarm.toolkit;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.springframework.core.io.ClassPathResource;

import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

public class GlobalConfig {
	// 期货60分钟短期周期数
	public static final int FUTURE_60MIN_SHORT_NUM = 7;
	
	// 期货60分钟中期周期数
	public static final int FUTURE_60MIN_MIDDLE_NUM= 50;
	
	// 股票60分钟短期周期数
	public static final int STOCK_60MIN_SHORT_NUM = 7;
		
	// 股票60分钟中期周期数
	public static final int STOCK_60MIN_MIDDLE_NUM = 50;
	
	// 60分钟均线斜率分数
	public static final int SCORE_60MIN_SMA_SLOPE = 10;
	
	// 60分数现价与均线的关系
	public static final int SCORE_60MIN_CLOSE_SMA_RELA = 10;
	
	// 60分钟MACD的值
	public static final int SCORE_60MIN_MACD_VALUE = 10;
	
	// 现价与日线55日均线的关系
	public static final int SCORE_DAY_CLOSE_55SMA_RELA = 20;
	
	// 日线55日均线的斜率
	public static final int SCORE_DAY_55SMA_SLOPE = 20;
	
	// 日线MACD的值
	public static final int SCORE_DAY_MACD_VALUE = 10;
	
	// 日线MACD的diff的值
	public static final int SCORE_DAY_MACD_DIFF = 5;
	
	// 日线MACD的dea的值
	public static final int SCORE_DAY_MACD_DEA = 5;
	
	// 日线MACD的diff与dea的关系
	public static final int SCORE_DAY_MACD_DIFF_DEA_RELA = 10;
	
	// 60分钟最高最低价位周期数
	public static final int ALARM_60MIN_MAXMIN_BAR_CNT = 60;
	
	// 日线现价与55日偏离度
	public static final int SCORE_DAY_PLD_LEVEL1 = 20;
	public static final int SCORE_DAY_PLD_LEVEL2 = 10;
	
	// 超过这个分数才进行通知
	public static final int NOTI_SCORE = 0;
	
	// HTTP请求超时时间
	public static final int HTTP_TIMEOUT = 3000;
	
	// HTTP请求最大尝试次数
	public static final int HTTP_MAX_TRY = 3;

	public static Map<String, String> code2Nice = new HashMap<>();
	public static Map<String, String> cngold2Sina = new HashMap<>();
	
	public static String[] sinaCodeList = new String[]{
			"AU1912", "AU0", "I2001", "I0",
			"RB2001", "RB0", "J2001", "J0",
			"Y2001", "Y0", "SR2001", "SR0",
			"TA2001", "TA0", "RU2001", "RU0",
			"CU1912", "CU0", "NI1912", "NI0",
			"AG1912", "AG0", "EG2001", "EG0",
			"MA2001", "MA0", "BU1912", "BU0",
			"P2001", "P0"};
	
	public static String[] cngoldCodeList = new String[]{
			// 焦炭，铁矿石，螺纹钢
			"JO_166003", "JO_165977", "JO_165681",
			// 橡胶,豆油，白糖，
			"JO_165668", "JO_165951", "JO_166055", 
			// PTA，铜，镍
			"JO_166029", "JO_165655", "JO_165590",
			// 金，银，甲醇
			"JO_165732", "JO_165757", "JO_166093",
			// 沥青，棕榈
			"JO_165694", "JO_165964"
	};
	
	public static String[] stockCodeList = new String[] {
		"sh000001", "sh000300", "sz399006"
	};
	
	public static void init() throws IORuntimeException, IOException {
		ClassPathResource hs300Res = new ClassPathResource("data/hs300.json");
		String hs300Json = IoUtil.read(hs300Res.getInputStream(), "utf-8");

		JSONArray ja = JSONUtil.parseArray(hs300Json);
		for (int i = 0; i < ja.size(); ++i) {
			JSONObject item = ja.getJSONObject(i);
			String code = item.getStr("code");
			if (code.startsWith("60")) {
				code = "sh" + code;
			} else {
				code = "sz" + code;
			}
			stockCodeList = ArrayUtil.append(stockCodeList, code);
			code2Nice.put(code, item.getStr("name"));
		}
		
		code2Nice.put("JO_166003", "焦炭连续");
		code2Nice.put("JO_165977", "铁矿连续");
		code2Nice.put("JO_165681", "螺纹连续");
		code2Nice.put("JO_165668", "橡胶连续");
		code2Nice.put("JO_165951", "豆油连续");
		code2Nice.put("JO_166055", "白糖连续");
		code2Nice.put("JO_166029", "PTA连续");
		code2Nice.put("JO_165655", "铜连续");
		code2Nice.put("JO_165590", "镍连续");
		code2Nice.put("JO_165732", "黄金连续");
		code2Nice.put("JO_165757", "白银连续");
		code2Nice.put("JO_166093", "甲醇连续");
		code2Nice.put("JO_165694", "沥青连续");
		code2Nice.put("JO_165964", "棕榈连续");

		cngold2Sina.put("JO_166003", "J0");
		cngold2Sina.put("JO_165977", "I0");
		cngold2Sina.put("JO_165681", "RB0");
		cngold2Sina.put("JO_165668", "RU0");
		cngold2Sina.put("JO_165951", "Y0");
		cngold2Sina.put("JO_166055", "SR0");
		cngold2Sina.put("JO_166029", "TA0");
		cngold2Sina.put("JO_165655", "CU0");
		cngold2Sina.put("JO_165590", "NI0");
		cngold2Sina.put("JO_165732", "AU0");
		cngold2Sina.put("JO_165757", "AG0");
		cngold2Sina.put("JO_166093", "MA0");
		cngold2Sina.put("JO_165694", "BU0");
		cngold2Sina.put("JO_165964", "P0");
	}

}
